//
//  ViewController2.m
//  20202
//
//  Created by student on 16/3/16.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController2.h"
#import "ViewController.h"
@interface ViewController2 ()
@property (weak, nonatomic) IBOutlet UIView *uiview;
@property (weak, nonatomic) IBOutlet UITextField *textred;
@property (weak, nonatomic) IBOutlet UITextField *textgreen;
@property (weak, nonatomic) IBOutlet UITextField *textblue;
@property (weak, nonatomic) IBOutlet UISlider *slider1;
@property (weak, nonatomic) IBOutlet UISlider *slider2;
@property (weak, nonatomic) IBOutlet UISlider *slider3;
@property(strong,nonatomic) NSUserDefaults *d;

@end

@implementation ViewController2

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.d=[NSUserDefaults standardUserDefaults];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)changecolor
{
    [self.uiview setBackgroundColor:[UIColor colorWithRed:[self.textred.text floatValue]/255.0  green:[self.textgreen.text floatValue]/255.0 blue:[self.textblue.text floatValue]/255.0 alpha:255/255.0]];
    [self.d setObject:self.textred.text forKey:@"red"];
    [self.d setObject:self.textblue.text forKey:@"blue"];
    [self.d setObject:self.textgreen.text forKey:@"green"];

}

- (IBAction)back:(id)sender
{
    [self.view endEditing:YES];
}

- (IBAction)slider1change:(UISlider *)sender
{
    int value=sender.value;
    self.textred.text=[NSString stringWithFormat:@"%i",value];
    [self changecolor];
}
- (IBAction)slider2change:(UISlider *)sender
{
    int value=sender.value;
    self.textgreen.text=[NSString stringWithFormat:@"%i",value];
    [self changecolor];
}
- (IBAction)slider3change:(UISlider *)sender
{
    int value=sender.value;
    self.textblue.text=[NSString stringWithFormat:@"%i",value];
    [self changecolor];
}
- (IBAction)textredchange:(UITextField *)sender
{
    float value=[sender.text floatValue];
    self.slider1.value=value;
    [self changecolor];
}
- (IBAction)textgreenchange:(UITextField *)sender
{
    float value=[sender.text floatValue];
    self.slider2.value=value;
    [self changecolor];
}
- (IBAction)textbluechange:(UITextField *)sender
{
    float value=[sender.text floatValue];
    self.slider3.value=value;
    [self changecolor];
}
- (IBAction)goback:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
